package com.sf.qo;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
public class PageResult {
    private List data;
    private Integer prevPage;
    private Integer nextPage;
    private Integer totalPage;
    private Integer currentPage;
    private Integer totalCount;
    private Integer pageSize;

    /**
     * 自己写入, 数据, 当前页, 页码大小, 总记录数
     *      另外三个自动创建
     * @param data
     * @param currentPage
     * @param pageSize
     * @param totalCount
     */
    public PageResult(List data, Integer currentPage, Integer pageSize, Integer totalCount) {
        this.data = data;
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;

        if (totalCount > 0) {
            this.totalPage = totalCount%pageSize==0?totalCount/pageSize:totalCount/pageSize+1;
            this.prevPage = Math.max(currentPage - 1, 1);
            this.nextPage = Math.min(currentPage + 1, totalPage);
        }
    }
}
